<!DOCTYPE html>
<html>
  <head>
    <title>Dynamic Components Example</title>
    <script src="./vue.js"></script>
    <style>
      .tab-button {
        padding: 6px 10px;
        border-top-left-radius: 3px;
        border-top-right-radius: 3px;
        border: 1px solid #ccc;
        cursor: pointer;
        background: #f0f0f0;
        margin-bottom: -1px;
        margin-right: -1px;
      }
      .tab-button:hover {
        background: #e0e0e0;
      }
      .tab-button.active {
        background: #e0e0e0;
      }
      .tab {
        border: 1px solid #ccc;
        padding: 10px;
      }
    </style>
  </head>
  <body>
   <h1>文档地址 https://cn.vuejs.org/v2/guide/components.html#动态组件</h1>
  
    <div id="dynamic-component-demo" class="demo">
      <button
        v-for="tab in tabs"
        v-bind:key="tab"
        v-bind:class="['tab-button', { active: currentTab === tab }]"
        v-on:click="currentTab = tab"
      >
        {{ tab }}
      </button>

      <component v-bind:is="currentTabComponent" class="tab"></component>
    </div>

    <script>
      //组件map
	  const tabMap={
				    "home": {
                          template: "<div>Home 组件</div>"
                     }
					 ,"posts": {
                        template: "<div>Posts 组件</div>"
                     }
					
					,"archive": {
                        template: "<div>Archive 组件</div>"
                    }
	 };
	  
	  
	  

      new Vue({
        el: "#dynamic-component-demo",
        data: {
          currentTab: "Home",
          tabs: ["Home", "Posts", "Archive"]
        },
		computed: {
		  currentTabComponent: function() {
		    const key=this.currentTab.toLowerCase();
            return tabMap[key];//返回对应的组件对象
          }
	    }
	});
    </script>
  </body>
</html>
